/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package imp.command;

import dom.Command;
import dom.Reciever;
import dom.workflow.WorkFlow;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author julian.pena
 */
public class ConcreteCommand implements Command{
    
    private WorkFlow workflow;
    private Reciever reciever;

    public ConcreteCommand(Reciever reciever) {
        this.reciever = reciever;
        reciever.setCommand(this);
    }

    @Override
    public void execute() throws Exception {
        reciever.action();
    }

    @Override
    public InputStream getInputStream() {
        return reciever.getInputStream();
    }

    @Override
    public void setInputStream(InputStream inputStream) {
        reciever.setInputStream(inputStream);
    }

    @Override
    public OutputStream getOutputStream() {
        return reciever.getOutputStream();
    }

    @Override
    public void setOutputStream(OutputStream outputStream) {
        reciever.setOutputStream(outputStream);
    }

    @Override
    public void run() {
        try {
            execute();
        } catch (Exception ex) {
            ex.printStackTrace();;
            this.notifyError();
        }
    }

    @Override
    public void setFather(WorkFlow workflow) {
        this.workflow = workflow;
    }

    @Override
    public void notifyStop(String fileName){
        workflow.notifyStop(this,fileName);
    }
    
    @Override
    public void stop(String fileName){
        reciever.stop(fileName);
    }
    
    @Override
    public boolean isInputReady(){
        return reciever.isInputReady();
    }
    
    @Override
    public boolean isOutputReady(){
        return reciever.isOutputReady();
    }

    @Override
    public void notifyError() {
        this.workflow.notifyError(this);
    }

    @Override
    public Reciever getReciever() {
        return reciever;
    }
    
    
}
